<?php
/* 访问记录类
 * @author  zhanghui
 * @create_date 2008-02-29
 */
class BabyVisitLog{
	
	function __construct(){}
	function __destruct(){}
	
	/* 增加一条访问记录 
	* @param $conn 数据库连接类
	* @param : array $arr_input - baby_id,baby_fid,friend_name,visit_date
	*/
	function addVisitLog($conn,$arr_input){
		$str_query = "insert into";
		$str_query .= " baby_visit_log";
		$str_query .= " set";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		$str_query .= ",baby_fid={$arr_input['baby_fid']}";
		$str_query .= ",friend_name={$arr_input['friend_name']}";
		$str_query .= ",visit_date='".$conn->getCurrentTime()."'";
		
		$conn->executeQuery($str_query);
	}
	
	/* 获得访问记录 
	* @param $conn 数据库连接类
	* @param : array $arr_input - baby_id,baby_fid,friend_name,visit_date
	*/
	function getVisitLogList($conn,$arr_input,$limit = null){
		$str_query = "select";
		if(isset($arr_input['cnt'])){
			$str_query .= " count(1)";
		}else{
			$str_query .= " baby_id";
			$str_query .= ",baby_fid";
			$str_query .= ",friend_name";
			$str_query .= ",visit_date";
		}
		$str_query .= " from";
		$str_query .= " baby_visit_log";
		$str_query .= " where";
		$str_query .= " baby_id={$arr_input['baby_id']}";
		if(isset($arr_input['baby_fid'])){
			$str_query .= " and baby_fid={$arr_input['baby_fid']}";
		}
		if(isset($arr_input['orderby'])){
			$str_query .= " order by {$arr_input['orderby']}";
		}
		if($limit != null){
			$str_query .= " {$limit}";
		}
		
		$arr_output = $conn->selectQuery($str_query);
		return $arr_output;
	}
	
}
?>